import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex)

export default ({
    state: {
        tabList: [],
        perms: [],
        hasRoute: false,

        editableTabsValue: 'Index',
        editableTabs: [
            {
                title: '首页',
                name: 'Index'
            }
        ],
    },
    mutations: {
        SET_TABLIST: (state,tabList) => {
            state.tabList = tabList
        },
        SET_PERMS: (state,perms) => {
            state.perms = perms
        },
        SET_HASROUTE: (state, hasRoute) => {
            state.hasRoute = hasRoute;
        },
        ADD_TABLETABS: (state, tab) => {
            let index = state.editableTabs.findIndex(v => v.name===tab.name);
            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name
                });
            }
            state.editableTabsValue = tab.name;
        },
        RESET_TABSTATE: (state) => {
            state.tabList = [];
            state.perms = [];
            // state.hasRoute = false;
            state.editableTabsValue = 'Index';
            state.editableTabs = [
                {
                    title: '首页',
                    name: 'Index'
                }
            ];
        }
    },
    actions: {
    },
    modules: {
    }
});